package com.dd.admin.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import com.dd.admin.service.AuthService;
import com.dd.common.dto.system.user.SysUserLoginDTO;
import com.dd.common.utils.AjaxResult;
import com.dd.common.vo.SysUserLoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@SaIgnore
@Slf4j
@Tag(name = "账号登录", description = "账号登录接口")
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private AuthService authService;

    @Operation(summary = "登录", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "登录数据",
            required = true,
            content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = SysUserLoginDTO.class))
    ))
    @PostMapping("/login")
    public AjaxResult<SysUserLoginVO> login(@Validated @RequestBody SysUserLoginDTO dto) {
        return AjaxResult.success(authService.login(dto));
    }

    @Operation(summary = "用户登出")
    @PostMapping("/logout")
    public AjaxResult<Object> logout() {
        StpUtil.logout();
        return AjaxResult.success();
    }


//    @Operation(summary = "获取滑块验证码")
//    @GetMapping("/auth/getCaptcha")
//    public AjaxResult<Captcha> getCaptcha() {
//        return AjaxResult.success(authService.getCaptcha());
//    }

//    @Operation(summary = "发送注册邮箱验证码")
//    @GetMapping("/sendEmailCode")
//    public AjaxResult<Boolean> sendEmailCode(String email) throws MessagingException {
//        return AjaxResult.success();
//    }
//
//    @Operation(summary = "邮箱账号注册")
//    @PostMapping("/api/email/register")
//    public AjaxResult<Boolean> register(@RequestBody EmailRegisterDto dto){
//        return AjaxResult.success(authService.register(dto));
//    }
//
//    @Operation(summary = "根据邮箱修改密码")
//    @PostMapping("/api/email/forgot")
//    public AjaxResult<Boolean> forgot(@RequestBody EmailRegisterDto dto){
//        return AjaxResult.success(authService.forgot(dto));
//    }
//
//    @Operation(summary = "获取微信扫码登录验证码")
//    @GetMapping("/api/wechat/getCode")
//    public AjaxResult<String> getWechatLoginCode(){
//        return AjaxResult.success(authService.getWechatLoginCode());
//    }
//
//    @Operation(summary = "获取微信扫码登录验证码")
//    @GetMapping("/api/wechat/isLogin/{loginCode}")
//    public AjaxResult<LoginUserInfo> getWechatIsLogin(@PathVariable String loginCode){
//        return AjaxResult.success(authService.getWechatIsLogin(loginCode));
//    }
//
//    @Operation(summary = "微信小程序登录")
//    @GetMapping("/api/wechat/appletLogin/{code}")
//    public AjaxResult<LoginUserInfo> appletLogin(@PathVariable String code){
//        return AjaxResult.success(authService.appletLogin(code));
//    }
//
//    @GetMapping("/auth/info")
//    public AjaxResult<LoginUserInfo> getUserInfo(@RequestParam(defaultValue = "admin") String source) {
//        return AjaxResult.success(authService.getLoginUserInfo(source));
//    }
}
